package dao;

import java.util.LinkedList;
import java.util.List;
import entities.Album;
import entities.CreditCard;

public class CreditCardDAO {

	private static final CreditCardDAO instance = new CreditCardDAO();
	private List<CreditCard> cCards;
	
	private CreditCardDAO(){
		cCards = new LinkedList<CreditCard>();
		CreditCard cus = null;
		
		cus = CreditCard.newInstance("jaime", "Jaime", "Vazquez", "ja@j.com", 1L, "test", "kl", "1", "00778", "PR", "Gurabo", "USA");
		cCards.add(cus);
		cus = CreditCard.newInstance("jaime1", "Jaime", "Vazquez", "ja@j.com", 2L, "test", "kl", "1", "00778", "PR", "Gurabo", "USA");
		cCards.add(cus);
	}
	
	public static CreditCardDAO getInstance() {
		return instance;
	}

	public synchronized CreditCard findCC(String creditCardNum) {
		CreditCard result = null;
		for (CreditCard s : cCards){
			if (s.getCreditCardNum().equals(creditCardNum)){
				result = s;
			}
		}
		return result;
	}

	public synchronized void addCC(CreditCard obj) throws RecordDuplicateException{
		if (findCC(obj.getCreditCardNum()) != null){
			throw new RecordDuplicateException("Credit Card with id: " + obj.getCreditCardNum() + " is already in the db.");
		}
		else {
			cCards.add(obj);
		}
	}

}
